package atguigu.gson;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

import java.lang.reflect.Type;
import java.util.List;

public class Demo {

    public static void main(String[] args) {

        String str = "[{\"codeType\":\"S\",\"description\":\"武汉\"},{\"codeType\":\"C\",\"description\":\"北京\"},{\"codeType\":\"B\",\"description\":\"长沙\"},{\"codeType\":\"W\",\"description\":\"深圳\"}]";

        Gson gson = new Gson();
        Type type = new TypeToken<List<LevelTypeInfo>>() {
        }.getType();
        List<LevelTypeInfo> lst = gson.fromJson(str,type);
        lst.stream().forEach(e->{
            System.out.println(e.getCodeType());
            System.out.println(e.getDescription());
        });

    }
}
